package cn.dlc.com.linear;

/**
 * @author 邓立川
 * @date 2021/3/18 7:33
 * @desc 链表测试类
 */
public class LinkListTest {

    public static void main(String[] args) {
        LinkList<String> strs = new LinkList<>();

        strs.insert("lucy");
        strs.insert("jack");
        strs.insert("lily");
        strs.insert("james");

        strs.insert(2,"yaoming");

        for (String str : strs) {
            System.out.println(str);
        }

        System.out.println("索引为3的元素是：" +  strs.get(3));

        String remove = strs.remove(1);
        System.out.println("删除的元素是：" + remove);

        for (String str : strs) {
            System.out.println(str);
        }

        LinkList<Integer> reverseTest = new LinkList<>();
        reverseTest.insert(1);
        reverseTest.insert(2);
        reverseTest.insert(3);
        reverseTest.insert(4);
        reverseTest.insert(5);
        reverseTest.insert(6);

        reverseTest.reverse();
        System.out.println("反转之后的顺序为：" + reverseTest.getN());
        for (Integer str : reverseTest) {
            System.out.println(str);
        }

        System.out.println("中间节点是：" +reverseTest.getMid());

        // 证明这个环
        Node<String> a = new Node<>("a",null);
        Node<String> b = new Node<>("b",null);
        Node<String> c = new Node<>("c",null);
        Node<String> d = new Node<>("d",null);
        Node<String> e = new Node<>("e",null);
        Node<String> f = new Node<>("f",null);
        Node<String> g = new Node<>("g",null);
        Node<String> h = new Node<>("h",null);
        a.setNext(b);
        b.setNext(c);
        c.setNext(d);
        d.setNext(e);
        e.setNext(f);
        f.setNext(g);
        g.setNext(h);
        h.setNext(c);

        Node<String> stringNode = strs.circleEnter(a);
        System.out.println("是否有环"+strs.hasCircle(a)+"入口是：" + stringNode.getItem());

    }
}
